package com.lhq.plugin.handler.mybatis;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.texteditor.ITextEditor;

import com.lhq.plugin.console.EclipseOutput;
import com.lhq.plugin.handler.BaseHandler;
import com.lhq.plugin.toolkit.MybatisLogsToolkit;

public class MybatisHandler extends BaseHandler {
    private static final String VIEW_NAME = "org.eclipse.ui.console.ConsoleView";

    @Override
    public Object execute(ExecutionEvent event) throws ExecutionException {
        ITextEditor ite = super.getTextEditor();
        IViewPart viewPart = super.getViewPart(ite, VIEW_NAME);
        String selectText = super.getSelectText(viewPart);

        this.handler(selectText);
        return null;
    }

    private void handler(String text) {
        if (StringUtils.isBlank(text)) {
            return;
        }
        MybatisLogsToolkit.parseText(text, EclipseOutput.output);
    }

}
